<template>
  <div class="app-container">
    <div>
      <!-- 搜索区域 -->
      <el-form ref="queryRef" :model="queryParams" :inline="true">
        <el-form-item label="赛事时间">
          <el-date-picker
            v-model="queryParams.date1"
            type="datetimerange"
            range-separator="至"
            value-format="YYYY-MM-DD HH:mm:ss"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </el-form-item>
        <el-form-item label="报名时间">
          <el-date-picker
            v-model="queryParams.date2"
            type="datetimerange"
            range-separator="至"
            value-format="YYYY-MM-DD HH:mm:ss"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </el-form-item>
        <el-form-item label="赛事报名">
          <el-input v-model="queryParams.name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="search"
            >搜索</el-button
          >
          <el-button type="info" icon="Refresh" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格数据 -->
      <el-table
        v-loading="loading"
        :data="list"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="index" width="55" align="center" label="序号" />
        <el-table-column
          label="赛事名称"
          prop="name"
          align="center"
          min-width="120"
        />
        <el-table-column
          label="赛事类型"
          prop="typeStr"
          align="center"
          min-width="120"
        />

        <el-table-column
          label="报名时间"
          prop="signTimeStr"
          align="center"
          min-width="260"
        />
        <el-table-column
          label="赛事时间"
          prop="matchTimeStr"
          align="center"
          min-width="260"
        />
        <el-table-column
          label="报名形式"
          prop="signTypeStr"
          align="center"
          min-width="80"
        />
        <el-table-column
          label="报名团队数"
          prop="signGroups"
          align="center"
          min-width="120"
        />
        <el-table-column
          label="报名人数"
          prop="signers"
          align="center"
          min-width="120"
        />

        <el-table-column
          label="操作"
          align="center"
          fixed="right"
          class-name="small-padding"
          width="200"
        >
          <template #default="scope">
            <!-- <el-button type="text" @click="viewRow(scope.row)">详情</el-button> -->
            <el-button type="text" @click="updateRow(scope.row)"
              >报名审核</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        :total="total"
        @pagination="initData"
      />
    </div>
  </div>
</template>

<script setup>
import { useRouter, useRoute } from "vue-router";
import { getCurrentInstance } from "vue";
import { reactive } from "@vue/runtime-core";
import { listByLeagueId } from "@/api/match/list.js";
const router = useRouter();
const route = useRoute();
const leagueId = ref(route.query.id);
const loading = ref(false);
const list = ref([]);
const total = ref();
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    type: "-1",
  },
});
const { queryParams } = toRefs(data);

initData();
async function initData() {
  queryParams.value.timeRange = queryParams.value.date1?.join();
  queryParams.value.signTimeRange = queryParams.value.date2?.join();
  queryParams.value.leagueId = leagueId.value;
  let res = await listByLeagueId(queryParams.value);
  list.value = res.rows;
  total.value = res.total;
  console.log(res);
}

// 收搜
function search() {
  initData();
}

function reset() {
  queryParams.value.type = "-1";
  queryParams.value.pageNum = 1;
  queryParams.value.pageSize = 10;
  queryParams.value.name = "";
  queryParams.value.date1 = [];
  queryParams.value.date2 = [];

  initData();
}

// 详情;
function viewRow(row) {
  router.push({
    path: "/match/trainReview",
    query: {
      id: row.id,
      active: 0,
      typeStr: row.typeStr,
      signType: row.signType,
      groups: row.signGroups,
      signers: row.signers,
    },
  });
}
// 报名审核;
function updateRow(row) {
  if (row.type == 1) {
    router.push({
      path: "/match/leaguAudit",
      query: {
        id: row.id,
        flag: 3,
      },
    });
  } else {
    router.push({
      path: "/match/trainReview",
      query: {
        id: row.id,
        typeStr: row.typeStr,
        groups: row.signGroups,
        signers: row.signers,
      },
    });
  }
}
</script>

<style lang="scss" scoped></style>
